<template>
	<view class="container">
    <view class="list" v-if="addressList.length">
      <view class="item" v-for="(item, index) in addressList" :key="index">
          <view class="left">
              <view class="name">{{item.province}}&nbsp;{{item.city}}&nbsp;{{item.district}}<text v-if="item.is_default">默认</text></view>
              <view class="card-no">{{item.real_name}}·{{item.phone}}</view>
          </view>
          <view class="right" @tap="editTenant(item)">
            <text class='iconfont icon-bianji' style="color: #008DFF;"></text>
            <!-- 编辑 <view class="iconfont icon-jiantou _font-10" style="color: #bdbdbd;margin-left: 8rpx;"></view> -->
          </view>
      </view>
    </view>
    <view class="no-tenant-box" v-if="addressList.length < 1 && page > 1">
      <image src="./static/no_tenant.png" class="no-tenant-img" />
      <view class="text">暂无收件信息</view>
    </view>
    <view class="operate-box" @tap="addTenant">新增收件信息</view>
	</view>
</template>

<script>
  import {
  	getAddressList,
  } from '@/api/user.js';
  
	export default {
		data() {
			return {
        date: '',
        addressList: [],
        loading: false,
        loadend: false,
        loadTitle: this.$t(`加载更多`),
        page: 1,
        limit: 20,
			}
		},
      onLoad(options) {
        
      },
      onShow: function() {
      	this.getAddressList(true);
      },
      methods: {
              /**
               * 获取地址列表
               * 
               */
              getAddressList: function(isPage) {
                let that = this;
                if (isPage) {
                  that.loadend = false;
                  that.page = 1;
                  that.$set(that, 'addressList', []);
                };
                if (that.loading) return;
                if (that.loadend) return;
                that.loading = true;
                that.loadTitle = '';
                getAddressList({
                  page: that.page,
                  limit: that.limit
                }).then(res => {
                  let list = res.data;
                  let loadend = list.length < that.limit;
                  that.addressList = that.$util.SplitArray(list, that.addressList);
                  that.$set(that, 'addressList', that.addressList);
                  that.loadend = loadend;
                  that.loadTitle = loadend ? that.$t(`我也是有底线的`) : that.$t(`加载更多`);
                  that.page = that.page + 1;
                  that.loading = false;
                }).catch(err => {
                  that.loading = false;
                  that.loadTitle = that.$t(`加载更多`);
                });
              },
              bindDateChange: function(e) {
                  this.date = e.detail.value
              },
              addTenant(){
                uni.navigateTo({
                  url: `/pages/info_setting/add_edit_delivered_info`
                })
              },
              editTenant(item){
                uni.navigateTo({
                  url: `/pages/info_setting/add_edit_delivered_info?delivered_info=` + encodeURIComponent(JSON.stringify(item))
                })
              }
      }
	}
</script>

<style lang="scss" scoped>
	page {
    min-height: 100vh;
		background-color: rgb(248,249,252);
	}
  .no-tenant-box{
    .no-tenant-img{
      width: 360rpx;
      height: 360rpx;
      display: block;
      margin: 200rpx auto 10rpx;
    }
    .text{
      text-align: center;
      font-size: 26rpx;
      color: #B9B9BD;
    }
  }
	.container {
		padding: 32rpx;
	}
  .list{
    
  }
  .item{
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #FFF;
    font-size: 28rpx;
    color: rgba(0,0,0,0.9);
    padding: 32rpx 28rpx;
    border-radius: 10rpx;
    margin-bottom: 24rpx;
    .left{
      .name{
        margin-bottom: 24rpx;
        font-weight: 500;
        font-size: 32rpx;
        color: #111E36;
        text{
          margin-left: 12rpx;
          padding: 8rpx 12rpx;
          background: #F8F9FC;
          border-radius: 8rpx 8rpx 8rpx 8rpx;
          font-size: 24rpx;
          color: #FF5700;
        }
      }
      .card-no{
        font-size: 28rpx;
        color: rgba(0,0,0,0.6);
      }
    }
    .right{
      display: flex;
      align-items: center;
      font-size: 28rpx;
      color: rgba(0,0,0,0.4);
    }
  }
  .operate-box{
    width: 686rpx;
    height: 96rpx;
    line-height: 96rpx;
    margin: 200rpx auto 30rpx;
    box-sizing: border-box;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    font-weight: 600;
    font-size: 32rpx;
    color: #FFFFFF;
    background: #008DFF;
    text-align: center;
    border-radius: 12rpx;
  }
</style>
